<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div v-mydir='"yellow"'>hello</div>
        <div v-mydir='"green"'>hello</div>
        <div v-mydir='flag ? "pink":"tomato"'>hello</div>
        <button @click='flag=!flag'>按钮</button>
    </div> 
    <script src="./js/vue.js"></script>
    <script>
        Vue.directive('mydir', {
            // inserted(el, binding) {
            //     el.style.cssText = `background:${binding.value}`
            //     console.log(binding)
            // }

            inserted(el, { value = 'red' }) {
                el.style.cssText = `background:${value}`
                console.log(value)
            },
            update(el, { value = 'red' }) {
                el.style.cssText = `background: ${value}`
                console.log(value)
            }
        })
        const vm = new Vue({
            el: '#app',
            data: {
                flag: true
            }
        })
    </script>
</body>

</html>